import Vue from 'vue'
import VueRouter from 'vue-router'
// 四个界面路由组件
import Home from '../views/home.vue'
import Person from '../views/person.vue'
import Infor from '../views/infor.vue'
// 导入新闻资讯相关组件
import Newlist from '../components/newList.vue'
import NewInfor from '../components/newsInfor.vue'
// 导入新品推荐相关组件
import Xptj from '../components/xptj.vue'
// 导入商品详情组件
import PDIF from '../components/productInfor.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/shop/xptj/infor',
    component: PDIF
  },
  {
    path: '/shop/xptj',
    component: Xptj
  },
  {
    path: '/person',
    component: Person
  },
  {
    path: '/msg',
    component: Infor
  },
  {
    path: '/home/newlist',
    component: Newlist
  },
  {
    path: '/home/newlist/:id',
    component: NewInfor
  },
  {
    path: '/home/xptj',
    component: Xptj
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/msg') {
    return next('/person')
  } else {
    return next()
  }
})

export default router
